class Queue {
  constructor(size) {
    this._container = new Array(size);
    this._start = 0;
    this._end = 0;
    this._limit = this.container.length - 1;
    this._used = 0;
  }
  nomalize() {
    const start = -this._start;
    const list = this._container;

    for (let i = 0; i < this._used; i++) {
      list[i] = list[start + i];
    }

    this._start = 0;
    this._end = this._used;
  }
  enQueue(val) {
    if (this._used === this._limit) {
      console.error("超出队列范围");
    } else {
      if (this._end === this._limit) {
        this.nomalize();
      }
      this._used++;
      this._container[this._end++] = val;
    }

    return this;
  }
  deQueue() {
    if (this._used == 0) {
      return console.error("队列无数据");
    }

    const res = this._container[this._start++];
    this._used--;
    
    return res
  }
}

